﻿using B.S.Ingredients.APIRead.Application.Command.ImmunityCommand;
using B.S.Ingredients.Domain;
using B.S.Ingredients.ErrorCode;
using B.S.Ingredients.Infartructrue.Interfaces;
using MediatR;

namespace B.S.Ingredients.APIRead.Application.CommandHandler.ImmunityCommandHandler
{
    public class ImmunitCreateCommandHandler : IRequestHandler<ImmunitCreateCommand, APIResult<int>>
    {
        public ImmunitCreateCommandHandler(IBaseRepository<Immunity> immuntyRepository)
        {
            ImmuntyRepository = immuntyRepository;
        }

        public IBaseRepository<Immunity> ImmuntyRepository { get; }

        public async Task<APIResult<int>> Handle(ImmunitCreateCommand request, CancellationToken cancellationToken)
        {
           
            request.Data.isDel = false;
            var path = await ImmuntyRepository.CreateAsync(request.Data);
            return new APIResult<int>
            {
                Code = ResultCode.success,
                Mag = "",
                Data = path
            };
        }
    }
}
